import Vue from 'vue'
import Router from 'vue-router'

import Home from '../layout/home'



import { getToken } from '@/utils/auth' // 验权(从cookie中获取)


Vue.use(Router)

export const router = [
  {
    path: '/',
    redirect: '/home',
    hidden:true,
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login'),
    hidden:true,
    meta: {
      requiresAuth: false
    }
  },
  {
    path: '/redirect',
    name: 'redirect',
    hidden: true,
    component: Home,
    meta: {
      requiresAuth: true,
    },
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/pages/redirect/index')
      }
    ],
  },
  {
    path: '/home',
    name: 'home',
    title: '首页',
    redirect: '/home/index',
    component: Home,
    meta: {
      requiresAuth: true,
      title: '首页',
    },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/pages/index'),
        title: '首页',
        meta: {
          requiresAuth: true,
          title: '首页',
          affix: true,
        }
      },

    ],
  },


];

// 注册路由
export default new Router({
  mode:'history', // 默认为'hash'模式
  routes: router,
})

// export default router;

// // 同步方式
// const _import = file => require('@/pages/' + file + '.vue').default;

// 异步方式
const _import = ()=>import('@/pages/' + file);
// component: _import(path)


// 需要权限的页面
export const asyncRouterMap = [
  {
    path: '/chart',
    name: 'chart',
    title: '图表',
    redirect: '/chart/number',
    component: Home,
    children: [
      {
        path: 'number',
        name: 'number',
        component: () => import('@/pages/number/number'),
        title: 'iView带搜索框表格',
        meta: {
          icon: '',
          title: 'iView带搜索框表格',
        },
      },
      {
        path: 'tableView',
        name: 'tableView',
        component: () => import('@/pages/table/table'),
        title: 'element-ui表格',
        meta: {
          icon: '',
          title: 'element-ui表格',
        }
      },
      {
        path: 'echarts',
        name: 'echarts',
        component: () => import('@/pages/number/echarts'),
        title: '图表',
        meta: {
          icon: '',
          title: '图表',
        },
      },
      {
        path: 'icon',
        name: 'icon',
        component: () => import('@/pages/icon/index'),
        title: '图标',
        meta: {
          icon: '',
          title: '图标',
        },
      },
    ],
  },

  {
    path: '/eCharts',
    name: 'eCharts',
    title: 'Charts',
    redirect: '/eCharts/keyboard',
    component: Home,
    children: [
      {
        path: 'keyboard',
        name: 'keyboard',
        component: () => import('@/pages/echart/keyBoard'),
        title: 'Keyboard',
        meta: {
          title: 'Keyboard',
        }
      },
      {
        path: 'lineMarker',
        name: 'lineMarker',
        component: () => import('@/pages/echart/lineMarker'),
        title: 'LineMarker',
        meta: {
          title: 'LineMarker',
        }
      },
      {
        path: 'mixChart',
        name: 'mixChart',
        component: () => import('@/pages/echart/mixChart'),
        title: 'MixChart',
        meta: {
          title: 'MixChart',
        }
      },



    ]
  },


];

